package com.qf.service.impl;

import com.qf.entity.Course;
import com.qf.entity.CourseDetails;
import com.qf.entity.CourseDetailsTeachers;
import com.qf.entity.CourseTeacher;
import com.qf.mapper.CourseDetailsMapper;
import com.qf.service.ICourseDetailsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qf.service.ICourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lcx
 * @since 2020-09-03
 */
@Service
public class CourseDetailsServiceImpl extends ServiceImpl<CourseDetailsMapper, CourseDetails> implements ICourseDetailsService {

    @Autowired
    private ICourseService courseService;

    @Override
    public List<CourseDetailsTeachers> selectDetail(Course course) {
        course = courseService.getById(course.getId());
        if (course == null){
            return null;
        }
        List<CourseTeacher> courseTeachers = courseService.selectCourseBy(course);
        CourseDetails courseDetail = getById(course.getDetailsId());

        CourseDetailsTeachers courseDetailsTeachers = new CourseDetailsTeachers();
        courseDetailsTeachers.setId(courseDetail.getId());
        courseDetailsTeachers.setDifficulty(courseDetail.getDifficulty());
        courseDetailsTeachers.setInfo(courseDetail.getInfo());
        courseDetailsTeachers.setTime(courseDetail.getTime());
        courseDetailsTeachers.setTitle(courseDetail.getTitle());
        courseDetailsTeachers.setTeachers(courseTeachers.get(0).getTeachers());
        courseDetailsTeachers.setDetailImages(courseDetail.getDetailImages());

        List list = new ArrayList();
        list.add(courseDetailsTeachers);
        return list;
    }
}
